<?php
    const HOST = 'localhost';
    const USERNAME = 'root';
    const PASSWORD = 'root';
    const DBNAME = 'shopping';

    $conn = mysqli_connect(HOST,USERNAME,PASSWORD,DBNAME);
    // var_dump($conn);

    if($conn->connect_error){
        die("连接失败:".$conn->connect_error);
    }


    $id=$_REQUEST['id'];

    // 查询数据库
    mysqli_select_db($conn,"shopping");
    $sql = "select * from goods where id like '$id'";
    

    mysqli_query($conn,"set names 'utf8'");
    $result = mysqli_query($conn,$sql);

$arrbb = array();
    
    if(mysqli_num_rows($result)>0){
        // 循环遍历，拿到每一条数据
        while($row = mysqli_fetch_assoc($result)){
            
            array_push($arrbb,$row);
            //将请求结果转换为json格式，微信是能对json格式的数据进行操作
            // echo json_encode($row,JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);
            // echo json_encode($row);
        }
        $res = array(
            'goodsshopping'=> $arrbb
          );
          echo json_encode($res,JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);

     
    }
?>
